/*
 *  POJ2533: Longest Ordered Subsequence
 */

/*-------- Includes --------*/
#include <iostream>
#include <algorithm>

using namespace std;

/*-------- Defines --------*/


/*-------- Types --------*/


/*-------- Global Variables --------*/
int N;
int a[1000];

int top;
int stk[1001];

/*-------- Function Prototypes --------*/


/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    cin >> N;

    for (int i = 0; i < N; i++) cin >> a[i];

    // initialize the stack
    top    = 1;
    stk[1] = a[0];

    // dynamic programming
    for (int i = 1; i < N; i++) {
        if (a[i] > stk[top]) {
            stk[++top] = a[i];
        } else {
            // *lower_bound(stk + 1, stk + top, a[i]) = a[i];
            int lo = 1, hi = top, key = a[i];
            while (hi > lo) {
                int mid = (hi + lo) / 2;

                if (key > stk[mid]) lo = mid + 1;
                else                hi = mid;
            }

            stk[lo] = key;
        }
    }

    cout << top << endl;
}

/*-------- Functions --------*/

